﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace 视频设备
{
    public partial  class 观众账号集
    {
        public enum AuthResult
        {
            Sucess, PassworDoesnotMatch, Locked,DoesnotMatch
        }
        
        
        /// <summary>
        /// 登录情况的判断
        /// </summary>
        /// <param name="name"></param>
        /// <param name="mima"></param>
        /// <returns></returns>
        public static AuthResult  auth(string name, string mima)
        {
            using (Model1Container db = new Model1Container())
            {
                观众账号 sh = new 观众账号();
                List<观众账号> sheb = (from u in db.观众账号集 where u.用户名 == name && u.密码 == mima select u).ToList();
                if (sheb.Count() > 0)
                {
                    List<观众账号> qu = (from u in db.观众账号集 where u.用户名 == name && u.权限 == "禁用" select u).ToList();
                    if (qu.Count() > 0)
                    {
                        return AuthResult.Locked;
                    }
                    else
                    {
                        return AuthResult.Sucess;
                    }
                }
                else
                {
                    return AuthResult .PassworDoesnotMatch;
                }
            }
        }

        //查询用户
        public static AuthResult  queryName(string name)
        {
            using (Model1Container db = new Model1Container())
            {
                观众账号 cm = new 观众账号();
                List<观众账号> mn = (from u in db.观众账号集 where u.用户名 == name select u).ToList();
                if (mn.Count() > 0)
                {
                    return AuthResult .Sucess ;
                }
                else
                {
                    return AuthResult.DoesnotMatch ;
                }
            }
        }

        //查询用户名和用户ID同时匹配
        public static AuthResult  queryNameId(string name, Int32  id)
        {
            using (Model1Container db = new Model1Container())
            {
                观众账号 cm = new 观众账号();
                List<观众账号> mn = (from u in db.观众账号集 where u.用户名 == name && u .用户ID == id select u).ToList();
                if (mn.Count() > 0)
                {
                    return AuthResult.Sucess;
                }
                else
                {
                    return AuthResult.DoesnotMatch;
                }
            }
        }


        //查询用户ID
        public static AuthResult  queryId(Int32  id)
        {
            using (Model1Container db = new Model1Container())
            {
                观众账号 cm = new 观众账号();
                List<观众账号> mn = (from u in db.观众账号集 where u.用户ID  == id select u).ToList();
                if (mn.Count() > 0)
                {
                    return AuthResult .Sucess ;
                }
                else
                {
                    return  AuthResult .DoesnotMatch ;
                }
            }
        }

        //找回密码时校验用户、问题、答案
        public static AuthResult queryUserQueAnser(string name, string wenti, string daan)
        {
            using (Model1Container db = new Model1Container())
            {
                观众账号 cm = new 观众账号();
                List<观众账号> mn = (from u in db.观众账号集 where u.用户名  == name && u.问题 ==wenti && u.答案 ==daan select u).ToList();
                if (mn.Count() > 0)
                {
                    return AuthResult.Sucess;
                }
                else
                {
                    return AuthResult.DoesnotMatch;
                }
            }
        }
    }
}